<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-minWidth="68px"
    >
      <!-- <el-form-item label="报表名称" prop="rptName">
        <el-input
          v-model="queryParams.rptName"
          placeholder="请输入报表名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="记录时间" prop="rptTime">
        <el-date-picker
          :editable="false"
          clearable
          size="small"
          v-model="queryParams.rptTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核人" prop="auditor">
        <el-input
          v-model="queryParams.auditor"
          placeholder="请输入审核人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="报表编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入报表编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['productionProcessRecord:productionProcessRecord:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['productionProcessRecord:productionProcessRecord:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="[
            'productionProcessRecord:productionProcessRecord:remove',
          ]"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="[
            'productionProcessRecord:productionProcessRecord:export',
          ]"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-s-check"
          size="mini"
          :disabled="multiple"
          @click="handleCheck"
          v-hasPermi="['productionProcessRecord:productionProcessRecord:check']"
          >审核</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="productionProcessRecordList"
      @selection-change="handleSelectionChange"
      max-height="550"
    >
      <el-table-column type="selection" minWidth="55" align="center" />
      <!-- <el-table-column label="编号" align="center" prop="id" minWidth="80px" /> -->
      <!-- <el-table-column label="报表名称" align="center" prop="rptName" /> -->
      <el-table-column
        label="记录时间"
        align="center"
        prop="rptTime"
        minWidth="100"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rptTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="供应商"
        align="center"
        prop="gysname"
        min-width="140px"
      />
      <!--  <el-table-column label="剩余数量" align="center" prop="sysl" />
      <el-table-column label="熏盖数量合计" align="center" prop="xgslhj" />
      <el-table-column label="使用数量合计" align="center" prop="syslhj" /> -->
      <!-- <el-table-column
        label="当日挑出不合格品"
        align="center"
        prop="unqualified"
      /> -->
      <el-table-column label="使用头数" align="center" prop="syts" />
      <el-table-column label="使用批次" align="center" prop="syps" />
      <el-table-column
        label="报表编码"
        align="center"
        prop="code"
        minWidth="160px"
      />
      <el-table-column
        label="工厂名称"
        align="center"
        prop="factory"
        minWidth="160px"
      />
      <el-table-column label="设备类型" align="center" prop="rptType" />

      <el-table-column label="操作人" align="center" prop="operator" />
      <el-table-column
        label="审核人"
        align="center"
        prop="auditor"
        width="70px"
      />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="250px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="excelhandleView(scope.row)"
            >导出</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="[
              'productionProcessRecord:productionProcessRecord:edit',
            ]"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="[
              'productionProcessRecord:productionProcessRecord:remove',
            ]"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改臭氧熏盖记录对话框 -->
    <!-- <el-dialog fullscreen :title="title" :visible.sync="open" minWidth="900px" append-to-body> -->
    <el-dialog
      fullscreen
      :title="title"
      :visible.sync="open"
      minWidth="900px"
      append-to-body
      custom-class="myDialog"
    >
      <TableHeader
        @nameChange="nameChange"
        @nameChange2="nameChange2"
        :data="{
          mainTitle: '臭氧熏盖记录',
          company: form.factory,
          code: form.code,
        }"
      />
      <el-form ref="form" :model="form" :rules="rules" label-minWidth="90px">
        <el-row>
          <!-- <el-col :span="12">
                <el-form-item label="报表名称" prop="rptName">
                  <el-input v-model="form.rptName" placeholder="请输入报表名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <el-col :span="12">
            <el-form-item label="记录日期" prop="rptTime">
              <el-date-picker
                :editable="false"
                clearable
                size="small"
                v-model="form.rptTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择记录时间"
                :disabled="openDisabled"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商" prop="gys" label-minWidth="120px">
              <!-- @dialogChange="form.gys = $event.value" -->
              <!-- <treeselect
                :searchable="false"
                v-model="form.gys"
                :options="deptOptions"
                zIndex="9999"
                :appendToBody="true"
                :normalizer="normalizer"
                placeholder="请选择设备厂家"
              /> -->
              <!-- <ReportDialog
                @dialogChange="form.gys = $event.value"
                :echoValue="form.gys"
                value="id"
                label="label"
                placeholder="选择设备厂家"
                :openDisabled="openDisabled"
              /> -->
              <treeselect
                v-model="form.gcjArray"
                :disable-branch-nodes="true"
                :options="dialogDataTree"
                :limit="6"
                placeholder="选择设备厂家"
                :normalizer="normalizer2"
                :searchable="false"
                :appendToBody="false"
                multiple
                @select="addSelect"
                :disabled="openDisabled"
                collapse-tags
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="使用头数" prop="syts">
              <el-input
                v-model="form.syts"
                placeholder="请输入使用头数"
                :disabled="openDisabled"
                type="number"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">

            <el-form-item
              label="剩余数量（箱）"
              label-minWidth="120px"
              prop="sysl"
            >
              <el-input
                :value="form.sysl"
                :disabled="openDisabled"
                type="number"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="使用批次" prop="syts">
              <el-input
                v-model="form.syps"
                placeholder="使用批次"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="氧气流量（升/分钟）" prop="yqll">
              <el-input
                v-model="form.yqll"
                placeholder="氧气流量"
                :disabled="openDisabled"
                type="number"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="12">
                <el-form-item label="报表编码" prop="code">
                  <el-input v-model="form.code" placeholder="请输入报表编码" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <!-- <el-col :span="12">
                <el-form-item label="工厂名称" prop="factory">
                  <el-input v-model="form.factory" placeholder="请输入工厂名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <!-- <el-col :span="12">
                <el-form-item label="设备类型" prop="rptType">
                  <el-select v-model="form.rptType" placeholder="请选择设备类型" :disabled="openDisabled">
                    <el-option label="请选择字典生成" value="" />
                  </el-select>
                </el-form-item>
            </el-col> -->
        </el-row>
        <br />
        <el-divider content-position="center">熏盖时间信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddRptProOzone1"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteRptProOzone1"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-upload2"
              size="mini"
              @click="$refs.rptProOzone1.bodyWrapper.scrollTop = 0"
              >置顶</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-download"
              size="mini"
              @click="
                $refs.rptProOzone1.bodyWrapper.scrollTop =
                  $refs.rptProOzone1.bodyWrapper.scrollHeight
              "
              >置底</el-button
            >
          </el-col>
        </el-row>
        <el-table
          :data="rptProOzone1List"
          maxHeight="500"
          :row-class-name="rowRptProOzone1Index"
          @selection-change="handleRptProOzone1SelectionChange"
          ref="rptProOzone1"
        >
          <el-table-column type="selection" minWidth="50" align="center" />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            minWidth="50"
          />
          <el-table-column label="开始时间" prop="kssj">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                v-model="scope.row.kssj"
                placeholder="选择时间"
                value-format="HH:mm"
                format="HH:mm"
                @change="triggerTime(scope)"
                :disabled="openDisabled"
              ></el-time-picker>
              <!-- <el-date-picker :editable="false" clearable size="small" v-model="scope.row.kssj" type="datetime"  value-format="yyyy-MM-dd HH:mm"  placeholder="选择开始时间" :disabled="openDisabled">
                </el-date-picker> -->
            </template>
          </el-table-column>
          <el-table-column label="结束时间" prop="jssj">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                v-model="scope.row.jssj"
                placeholder="选择时间"
                value-format="HH:mm"
                format="HH:mm"
                :disabled="openDisabled"
              ></el-time-picker>
              <!-- <el-date-picker :editable="false" clearable size="small" v-model="scope.row.jssj" type="date"  value-format="yyyy-MM-dd"  placeholder="选择结束时间" :disabled="openDisabled">
                </el-date-picker> -->
            </template>
          </el-table-column>
          <el-table-column label="生产批号" prop="scph">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.scph"
                placeholder="请输入生产批号"
                :disabled="openDisabled"
                @change="triggerTime2(scope)"
              />
            </template>
          </el-table-column>
          <el-table-column label="箱号" prop="xianghao">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.xianghao"
                placeholder="请输入箱号"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="使用情况" prop="syqk">
            <template slot-scope="scope">
              <!-- <el-input v-model="scope.row.syqk" placeholder="请输入使用情况" :disabled="openDisabled"/> -->
              <el-select v-model="scope.row.syqk" :disabled="openDisabled">
                <el-option value="已使用">已使用</el-option>
                <el-option value="未使用">未使用</el-option>
              </el-select>
            </template>
          </el-table-column>
          <!-- <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
                <el-input v-model="scope.row.remark" type="textarea" placeholder="请输入内容" :disabled="openDisabled"/>
            </template>
          </el-table-column> -->
        </el-table>

        <br />
        <el-divider content-position="center">瓶盖使用情况信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddRptProOzone2()"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteRptProOzone2"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-upload2"
              size="mini"
              @click="$refs.rptProOzone2.bodyWrapper.scrollTop = 0"
              >置顶</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-download"
              size="mini"
              @click="
                $refs.rptProOzone2.bodyWrapper.scrollTop =
                  $refs.rptProOzone2.bodyWrapper.scrollHeight
              "
              >置底</el-button
            >
          </el-col>
        </el-row>
        <el-table
          :data="rptProOzone2List"
          :row-class-name="rowRptProOzone2Index"
          @selection-change="handleRptProOzone2SelectionChange"
          ref="rptProOzone2"
          maxHeight="500"
        >
          <el-table-column type="selection" minWidth="50" align="center" />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            minWidth="50"
          />
          <el-table-column label="倒盖时间" prop="bhgsl">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                v-model="scope.row.bhgsl"
                placeholder="选择时间"
                value-format="HH:mm"
                format="HH:mm"
                :disabled="openDisabled"
              ></el-time-picker>
              <!-- <el-date-picker :editable="false" clearable size="small" v-model="scope.row.bhgsl" type="date"  value-format="yyyy-MM-dd"  placeholder="选择倒盖时间" :disabled="openDisabled">
                </el-date-picker> -->
            </template>
          </el-table-column>
          <el-table-column label="数量（只/箱）" prop="bhgyy">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.bhgyy"
                placeholder="请输入数量"
                :disabled="openDisabled"
                onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column label="熏盖记录" prop="brotherId">
            <template slot-scope="scope">
              <pxDialog
                @dialogChange="scope.row.brotherId = $event.value"
                :echoValue="scope.row.brotherName"
                :isMate="false"
                parameter="data"
                value="dictValue"
                label="dictLabel"
                :multiple="false"
                url="/productionProcess/productionProcessRecord/queryXH"
                :column="['箱号/dictLabel']"
                placeholder="请选择箱号"
                :openDisabled="openDisabled"
                :dialogData="dialogData"
              />
            </template>
            <!-- <template slot-scope="scope">
                <el-input v-model="scope.row.brotherId" placeholder="请输入熏盖记录" :disabled="openDisabled"/>
            </template> -->
            <!-- <div class="item">   -->
            <!-- <template slot-scope="scope">
              <el-select v-model="scope.row.brotherId" placeholder="请选择箱号" :disabled="openDisabled" filterable >
                <el-option
                  v-for="dict in xh"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </template> -->
            <!-- </div>   -->
          </el-table-column>
          <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.remark"
                placeholder="请输入内容"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-col :span="8">
            <el-form-item label="熏盖数量合计" label-minWidth="100px">
              <el-input
                :value="rptProOzone1List.length"
                :disabled="openDisabled"
                type="number"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="使用数量合计" label-minWidth="100px">
              <el-input
                :value="rptProOzone2List.length"
                :disabled="openDisabled"
                type="number"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="当日挑出不合格品"
              label-minWidth="100px"
              prop="unqualified"
            >
              <el-input v-model="form.unqualified" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核人" prop="auditor">
              <el-input v-model="form.auditor" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="操作人" prop="operator">
              <UserDialog
                @dialogChange="form.operator = $event.label"
                :echoValue="form.operator"
                :multiple="false"
                :openDisabled="openDisabled"
                placeholder="请选择人员"
              />
              <!-- <el-input
                v-model="form.operator"
                placeholder="请输入操作人"
                :disabled="openDisabled"
              /> -->
              <!--<el-select
                v-model="form.operator"
                filterable
                allow-create
                placeholder="请选择操作人"
                style="width: 100%"
                :disabled="openDisabled"
              >
                <el-option
                  v-for="item in userList"
                  :key="item.index"
                  :label="item.nickName"
                  :value="item.nickName"
                ></el-option>
              </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <template>
          <el-popconfirm
            title="确定提交吗？"
            @confirm="submitForm"
            cancel-button-type="Primary"
            icon-color="red"
          >
            <el-button type="primary" slot="reference">确 定</el-button>
          </el-popconfirm>
        </template>
        <template>
          <el-popconfirm
            title="确定关闭弹窗吗？"
            @confirm="cancel"
            style="margin-left: 10px"
            cancel-button-type="Primary"
            icon-color="red"
          >
            <el-button type="primary" slot="reference">取 消</el-button>
          </el-popconfirm>
        </template>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSelect2 } from "@/api/report/process/label";
import { list } from "@/api/dialog/index";
import {
  listProductionProcessRecord,
  getProductionProcessRecord,
  delProductionProcessRecord,
  addProductionProcessRecord,
  updateProductionProcessRecord,
  checkRptProOzoneRecord,
  getXH,
  queryXH,
  queryWSY,
  updateCheck,
} from "@/api/report/process/productionProcessRecord";

import { getInfo } from "@/api/login";
import { listUser } from "@/api/system/user";
import { listEqpfactory } from "@/api/basic/eqpfactory/eqpfactory";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "ProductionProcessRecord",
  components: { Treeselect },
  data() {
    return {
      /* 当前用户名 */
      nickName: "",
      userList: [],
      num: 0,
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      dialogDataTree: [],
      // 选中数组
      ids: [],
      ids1: [],
      xh: [],
      // 子表选中数据
      checkedRptProOzone1: [],
      // 子表选中数据
      checkedRptProOzone2: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 臭氧熏盖记录表格数据
      productionProcessRecordList: [],
      // 熏盖时间表格数据
      rptProOzone1List: [],
      // 瓶盖使用情况表格数据
      rptProOzone2List: [],
      // 树选项
      deptOptions: [],
      // 弹出层标题
      title: "",
      status: true,
      status2: true,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        rptName: null,
        rptTime: null,
        rptTime1: null,
        auditor: null,
        code: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      //熏盖记录列表
      dialogData: [],
    };
  },
  created() {
    this.getListfac();
    this.getList();
    this.getDialogData();
    this.queryUserList();
  },
  methods: {
    /** 转换数据结构 */
    normalizer2(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.label,
        children: node.children,
      };
    },
    addSelect(value) {
      console.log(value);
      // this.selectList = value.label
    },
    getListfac() {
      listSelect2().then((response) => {
        this.dialogDataTree = response.rows;
        // console.log(response.rows)
        // console.log(this.dialogData);
        // /*        this.selectionLabel = this.findPathByLeafId(
        //   this.echoValue,
        //   this.tableData
        // );*/
      });
    },
    //获取熏盖记录列表
    getDialogData() {
      list(
        "/productionProcess/productionProcessRecord/queryXH?total=0&pageNum=1&pageSize=1000000",
        "get"
      ).then((response) => {
        this.dialogData = response.data;
      });
    },
    dialogChange(event) {
      console.log(event);
      this.form.gys = event.value;
      this.form.gysname = event.label;
    },
    getXH() {
      getXH().then((response) => {
        this.xh = [];
        this.xh = response.data;
      });
    },

    queryXH() {
      queryXH().then((response) => {
        this.xh = [];
        response.data.forEach((item) => {
          let obj = {};
          obj.dictLabel = item.dictLabel;
          obj.dictValue = item.dictValue;
          this.xh.push(obj);
        });
      });
    },

    // getXH(){
    //   getXH().then((response) => {
    //           this.xh = response.data;
    //           console.log(response.data);
    //         });
    // },
    // 结束时间比开始时间多30分钟
    triggerTime(scope) {
      let l =
        new Date("2021-10-01 " + scope.row.kssj + ":00").getTime() + 1800000;
      // 时间戳格式工具
      var date = new Date(l);
      var hours =
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      var minutes =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      this.rptProOzone1List[scope.$index].jssj = hours + ":" + minutes;

      if (this.status2) {
        let bz = scope.row.identifier;
        this.rptProOzone1List.forEach((item) => {
          if (item.identifier == bz) {
            item.kssj = scope.row.kssj;
            item.jssj = hours + ":" + minutes;
          }
        });
        this.status2 = false;
      }
    },
    triggerTime2(scope) {
      if (this.status) {
        let bz = scope.row.identifier;
        this.rptProOzone1List.forEach((item) => {
          if (item.identifier == bz) {
            item.scph = scope.row.scph;
          }
        });
        this.status = false;
      }
    },
    /** 查询臭氧熏盖记录列表 */
    getList() {
      this.loading = true;
      listProductionProcessRecord(this.queryParams).then((response) => {
        this.productionProcessRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
        for (let item of this.productionProcessRecordList) {
          if (item.gysname!=''|| item.gysname!=null) {
            if (item.gysname.search(";") != -1) {
              item.gysname = item.gysname.split(";")[0];
            }
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rptName: null,
        rptTime: null,
        gys: null,
        gysname: null,
        sysl: null,
        xgslhj: null,
        syslhj: null,
        unqualified: null,
        syts: null,
        auditor: null,
        operator: this.nickName,
        code: "LK-QF-LS1-10-004-11-01",
        factory: "青岛崂山矿泉水有限公司",
        rptType: "臭氧熏盖",
        delFlag: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        syps:null,
        yqll:null,
      };
      this.rptProOzone1List = [];
      this.rptProOzone2List = [];
      this.resetForm("form");

      const myDate = new Date();
      const year = myDate.getFullYear();
      const month = myDate.getMonth() + 1;
      const day = myDate.getDate();
      this.form.rptTime = `${year}-${month}-${day}`;

      listEqpfactory().then((response) => {
        this.deptOptions = this.handleTree(response.data, "id");
      });
    },
    /** 转换数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },
    dialogChangeFactory(event, scope) {
      // console.log(event)
      //  this.rptProArrangesub1List[scope.$index].gys = event.value;
      //  this.rptProArrangesub1List[scope.$index].gysname = event.label;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.rptTime != null) {
        let arr = this.queryParams.rptTime;
        this.queryParams.rptTime = arr[0];
        this.queryParams.rptTime1 = arr[1];
      }

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      queryWSY().then((response) => {
        // console.log(response.data[0].sysl);
        var tempSysl = response.data[0].sysl;
        // console.log(tempSysl);
        // this.sysl=112;
        // this.form.sysl=tempSysl;
        // this.form.num=tempSysl;
        // this.num=tempSysl;
        this.form.sysl = tempSysl;
        this.form.yqll = "4.5";
        // this.form.sysl=response.data[0].sysl;
        // console.log(this.form);
      });
      this.openDisabled = false;
      this.open = true;
      this.title = "添加臭氧熏盖记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      this.queryXH();
      getProductionProcessRecord(id).then((response) => {
        this.form = response.data;
        this.rptProOzone1List = response.data.rptProOzone1List;
        this.rptProOzone2List = response.data.rptProOzone2List;
        this.open = true;
        this.title = "修改臭氧熏盖记录";

        var temp1 = response.data.rptProOzone1List;
        var tempnum = 0;
        for (var i = 0; i < temp1.length; i++) {
          // console.log(i);
          if (temp1[i].syqk == "未使用") {
            tempnum++;
            // console.log(tempnum);
          }
        }
        this.num = tempnum;
        // console.log(tempnum);
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      this.queryXH();
      getProductionProcessRecord(id).then((response) => {
        this.form = response.data;
        this.rptProOzone1List = response.data.rptProOzone1List;
        this.rptProOzone2List = response.data.rptProOzone2List;
        this.open = true;
        this.title = "查看臭氧熏盖记录";

        // var temp1 = response.data.rptProOzone1List;
        // var tempnum = 0;
        // for (var i = 0; i < temp1.length; i++) {
        //   // console.log(i);
        //   if (temp1[i].syqk == "未使用") {
        //     tempnum++;
        //     // console.log(tempnum);
        //   }
        // }
        // this.num = tempnum;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.rptProOzone1List = this.rptProOzone1List;
          this.form.rptProOzone2List = this.rptProOzone2List;
          if (this.form.id != null) {
            updateProductionProcessRecord(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProductionProcessRecord(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除臭氧熏盖记录编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delProductionProcessRecord(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 熏盖时间序号 */
    rowRptProOzone1Index({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 熏盖时间添加按钮操作 */
    handleAddRptProOzone1() {
      if (this.form.syts == null || this.form.syts == "") {
        this.msgError("请输入使用头数");
      } else {
        let num = Number(this.form.syts);
        let sj = Math.random();
        for (let i = 0; i < num; i++) {
          let obj = {};
          obj.kssj = "";
          obj.jssj = "";
          obj.scph = "";
          obj.xianghao = "";
          obj.syqk = "未使用";
          obj.remark = "";
          obj.identifier = sj;
          this.rptProOzone1List.push(obj);
        }
        this.status = true;
        this.status2 = true;
      }
    },
    /** 熏盖时间删除按钮操作 */
    handleDeleteRptProOzone1() {
      if (this.checkedRptProOzone1.length == 0) {
        this.$alert("请先选择要删除的熏盖时间数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        for (let i = this.rptProOzone1List.length - 1; i >= 0; i--) {
          this.checkedRptProOzone1.forEach((id) => {
            if (this.rptProOzone1List[i].index === id) {
              this.rptProOzone1List.splice(i, 1);
            }
          });
        }
      }
    },
    /** 单选框选中数据 */
    handleRptProOzone1SelectionChange(selection) {
      // if (selection.length > 1) {
      //   this.$refs.rptProOzone1.clearSelection();
      //   this.$refs.rptProOzone1.toggleRowSelection(selection.pop());
      // } else {
      //   this.checkedRptProOzone1 = selection;
      // }
      this.checkedRptProOzone1 = selection.map((item) => item.index);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "productionProcessRecord/productionProcessRecord/export",
        {
          ...this.queryParams,
        },
        "臭氧熏盖记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    excelhandleView(row) {
      this.download(
        "Laboratory/productionProcessRecord/exportexcel?id=" + row.id,
        {
          ...this.queryParams,
        },
        "臭氧熏盖记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    /** 瓶盖使用情况序号 */
    rowRptProOzone2Index({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 瓶盖使用情况添加按钮操作 */
    handleAddRptProOzone2() {
      let obj = {};
      if (this.rptProOzone2List.length == 0) {
        let date = new Date();
        let hours = date.getHours();
        let minutes = date.getMinutes();
        obj.bhgsl = hours + ":" + minutes;
      } else {
        let l =
          new Date(
            "2021-10-01 " +
              this.rptProOzone2List[this.rptProOzone2List.length - 1].bhgsl +
              ":00"
          ).getTime() + 900000;
        let temptime = new Date(l);
        let hours = temptime.getHours();
        let minutes = temptime.getMinutes();
        obj.bhgsl = hours + ":" + minutes;
        obj.bhgyy =
          this.rptProOzone2List[this.rptProOzone2List.length - 1].bhgyy;
      }
      // obj.bhgyy = "";
      obj.brotherId = "";
      obj.remark = "";
      this.rptProOzone2List.push(obj);
    },
    //接收编号
    nameChange(e) {
      this.form.code = e;
    },
    nameChange2(e) {
      this.form.factory = e;
    },
    /** 瓶盖使用情况删除按钮操作 */
    handleDeleteRptProOzone2() {
      if (this.checkedRptProOzone2.length == 0) {
        this.$alert("请先选择要删除的瓶盖使用情况数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.rptProOzone2List.splice(this.checkedRptProOzone2[0].index - 1, 1);
      }
    },
    /** 单选框选中数据 */
    handleRptProOzone2SelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.rptProOzone2.clearSelection();
        this.$refs.rptProOzone2.toggleRowSelection(selection.pop());
      } else {
        this.checkedRptProOzone2 = selection;
      }
    },
    /** 审核按钮操作 */
    handleCheck(row) {
      /* 审核 */
      this.ids.forEach((id) => {
        getProductionProcessRecord(id).then((response) => {
          if (response.data.auditor != null && response.data.auditor != "") {
            this.msgError(
              '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
            );
          } else {
            let obj = {};
            obj.id = id;
            obj.auditor = this.nickName;
            /* 修改 */
            checkRptProOzoneRecord(obj).then((response) => {
              this.msgSuccess('编号为"' + id + '"的数据项审核成功！');
              this.getList();
            });
          }
        });
      });
    },
    /* 查询用户列表 */
    queryUserList() {
      listUser().then((response) => {
        this.userList = response.rows;
      });
      getInfo().then((response) => {
        this.nickName = response.user.nickName;
      });
    },
  },
};
</script>
<style scoped>
.vue-treeselect__limit-tip-text{
  margin-top:-1rem;
}
</style>